/**
 * Copyright &copy; 2012-2016 <a href="https://git.oschina.net/zdw2016/webbase5">Webbase</a> All rights reserved.
 */
package com.foreveross.webbase.projectdemo.web;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.foreveross.webbase.common.config.Global;
import com.foreveross.webbase.common.persistence.Page;
import com.foreveross.webbase.common.web.BaseController;
import com.foreveross.webbase.projectdemo.entity.Projectapply;
import com.foreveross.webbase.projectdemo.entity.Serverinformation;
import com.foreveross.webbase.projectdemo.service.ProjectapplyService;
import com.foreveross.webbase.projectdemo.service.ServerinformationService;

/**
 * 审核管理Controller
 * @author yangwanli
 * @version 2017-03-16
 */
@Controller
@RequestMapping(value = "${adminPath}/projectdemo/serverinformation")
public class ServerinformationController extends BaseController {

	@Autowired
	private ServerinformationService serverinformationService;
	@Autowired
	private ProjectapplyService projectapplyService;
	
//	@RequiresPermissions("projectdemo:serverinformation:view")
//	@RequestMapping(value = {"list", ""})
//	public String list(Serverinformation serverinformation) {
//		Page<Serverinformation> page = serverinformationService.findPage(new Page<Serverinformation>(request(), response()), serverinformation);
//		attr("page", page);
//		return "projectdemo/serverinformationList";
//	}
//	
	/**
	 * 获取项目信息跳到projectinformationInf页面
	 * @param projectapply
	 * @return
	 */
	@RequiresPermissions("projectdemo:serverinformation:view")
	@RequestMapping(value = {"list", ""})
	public String projectList(Projectapply projectapply) {
		Page<Projectapply> page = projectapplyService.findPage(new Page<Projectapply>(request(), response()), projectapply); 
		attr("page", page);
		attr("aaa",projectapply);
		return "projectdemo/serverinformationList";
	}
	@RequiresPermissions("projectdemo:serverinformation:view")
	@RequestMapping("form")
	public String form(@RequestParam String id) {
		Serverinformation serverinformation=serverinformationService.get(id);
		attr("serverinformation", serverinformation);
		return "projectdemo/serverinformationForm";
	}
	@RequiresPermissions("projectdemo:serverinformation:view")
	@RequestMapping("formProjectId")
	public String formProjectId(@RequestParam String projectid) {
		Serverinformation serverinformation=serverinformationService.getProjectId(projectid);
		attr("serverinformation", serverinformation);
		return "projectdemo/serverinformationForm";
	}
	
	@RequiresPermissions("projectdemo:serverinformation:view")
	@RequestMapping("formInf")
	public String formInf(@RequestParam String projectid) {
			Serverinformation serverinformation=serverinformationService.getProjectId(projectid);
			attr("serverinformation", serverinformation);
		return "projectdemo/serverinformationInf";
	}
	
	/**
	 * 审核保存成功跳到projectinformationInf页面
	 * @param serverinformation
	 * @param redirectAttributes
	 * @return
	 */
	@RequiresPermissions("projectdemo:serverinformation:edit")
	@RequestMapping("save")
	public String save(Serverinformation serverinformation, RedirectAttributes redirectAttributes) {
		serverinformationService.save(serverinformation);
		addMessage(redirectAttributes, "保存审核成功");
		return "redirect:"+Global.getAdminPath()+"/projectdemo/serverinformation/?repage";
	}
}